
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
* @author :${author}
* @description: ${desc}服务接口实现类
* @create date: ${createDate}
*/

@Slf4j
@Service
@RequiredArgsConstructor
public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, ${entityName}${entitySuffix}> implements ${entityName}Service {

    @Autowired
    ${entityName}Mapper ${entityNameLower}Mapper;


    /**
    * 保存${desc}
    * @param ${entityNameLower}DTO
    * @return
    */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int add(${entityName}DTO ${entityNameLower}DTO) {
        return ${entityNameLower}Mapper.insert(copyTo${entityName}${entitySuffix}(${entityNameLower}DTO));
    }

    /**
    * 根据ID更新${desc}
    * @param ${entityNameLower}DTO
    * @return
    */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int update(${entityName}DTO ${entityNameLower}DTO) {
        return ${entityNameLower}Mapper.updateById(copyTo${entityName}${entitySuffix}(${entityNameLower}DTO));
    }

<#if primaryKey!='noPrimaryKey'>
    /**
    * 删除${desc}
    * @param ${primaryKey}
    * @return
    */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int remove(${javaKeyType} ${primaryKey}) {
        return ${entityNameLower}Mapper.deleteById(${primaryKey});
    }

    /**
    * 根据查询${desc}
    * @param ${primaryKey}
    * @return
    */
    @Override
    public ${entityName}VO detail(${javaKeyType} ${primaryKey}) {
        ${entityName}${entitySuffix} ${entityNameLower}= ${entityNameLower}Mapper.selectById(${primaryKey});
        return copyTo${entityName}VO(${entityNameLower});
    }
</#if>

    /**
    * 查询${desc}
    * @param ${entityNameLower}DTO
    * @return
    */
    @Override
    public List<${entityName}VO> findList(${entityName}DTO ${entityNameLower}DTO) {
        //TODO findList
        return null;
    }

    /**
    * 查询${desc}分页信息
    * @param ${entityNameLower}PageDTO
    * @return PageVO
    */
    @Override
    public IPage<${entityName}VO> findPageList(${entityName}PageDTO ${entityNameLower}PageDTO) {
        //TODO findPageList
        return null;
    }

    private ${entityName}${entitySuffix} copyTo${entityName}Entity(${entityName}DTO ${entityNameLower}DTO) {
        ${entityName}${entitySuffix} ${entityNameLower} = new ${entityName}${entitySuffix}();
        BeanUtils.copyProperties(${entityNameLower}DTO, ${entityNameLower});
        return ${entityNameLower};
    }

    private ${entityName}VO copyTo${entityName}VO(${entityName}${entitySuffix} ${entityNameLower}) {
        ${entityName}VO ${entityNameLower}VO=new ${entityName}VO();
        BeanUtils.copyProperties(${entityNameLower},${entityNameLower}VO);
        return ${entityNameLower}VO;
    }
}